<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="${pageContext.request.contextPath }/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/h-ui/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/h-ui/lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/h-ui/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/h-ui/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加花型图片</title>
</head>
<body>
<div class="pd-20">
  <form action="${pageContext.request.contextPath }/upload/uploadPattern" method="post" class="form form-horizontal" id="add_HomeMessage_Form" enctype="multipart/form-data">
    <div class="row cl">
    	<table id="patternImageTable" class="input tabContent">
			<tr>
				<td colspan="4">
					<a href="javascript:;" id="addImage" class="btn btn-primary radius">添加</a>
					<span>*宽度：590像素 *高度：1180像素  或宽度：590xN像素 高度：1180xN像素</span>
				</td>
			</tr>
			<tr>
				<td>
					<input type="file" name="patternImg" class="patternImageFile" />
				</td>
				<td>
					<a href="javascript:;" class="deletepatternImage">删除</a>
				</td>
			</tr>
		</table>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-2">
        <input type="button" onclick="uploadImg();" class="btn btn-primary radius" value="提交" />
      </div>
    </div>
  </form>
</div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/jquery-form.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/webuploader/0.1.5/webuploader.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/uploadSingleImg.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/uploadImg.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/jqthumb/jqthumb.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/tableBtnGroup.js"></script>
<script type="text/javascript">
var imageIndex = 0;
$("#addImage").click(function() {
		var trHtml ='<tr><td><input type="file" name="patternImg" class="patternImageFile" \/><\/td><td><a href="javascript:;" class="deletepatternImage">删除<\/a><\/td><\/tr>';
		$("#patternImageTable").append(trHtml);
		imageIndex ++;
		$("a.deletepatternImage").on("click", function() {
			var $this = $(this);
			$this.closest("tr").remove();
		});
});
$("a.deletepatternImage").on("click", function() {
	var $this = $(this);
	$this.closest("tr").remove();
});

function uploadImg(){
	var index1 = layer.load(1);
	$("#add_HomeMessage_Form").ajaxSubmit({
        type:'post',
        url:'${pageContext.request.contextPath }/upload/uploadPattern',
        success:function(data){
        	var failName=data.data.failName;
        	var failName2=data.data.failName2;
            if(data.data.count>0){
            	if(data.data.failName!=""){
            		if(failName==''){
            			failName=0;
            		}
            		if(failName2==''){
            			failName2=0;
            		}
            		
            		alert("共上传成功"+data.data.count+"张图片,其中"+failName+"上传失败，"+failName2+"上传尺寸不符合规范");
            	}else{
            		alert("上传成功，共上传"+data.data.count+"张图片");
            	}
            	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            	window.parent.location.reload();
               	parent.layer.close(index);
            }else{
            	if(failName==''){
        			failName=0;
        		}
        		if(failName2==''){
        			failName2=0;
        		}
            	alert("共上传成功"+data.data.count+"张图片,其中"+failName+"上传失败，"+failName2+"上传尺寸不符合规范");
            }
            layer.close(index1);
            
        },
        error:function(XmlHttpRequest,textStatus,errorThrown){
            console.log(XmlHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
            layer.close(index1);
        }
    });
	
}
</script>
</body>
</html>